import { defineStore } from 'pinia'

interface DeptInfo {
  deptId: number | null
  deptName: string
  accessibleDeptIds: number[]
}

export const useUserStore = defineStore('user', {
  state: () => ({
    token: '',
    deptInfo: { deptId: null, deptName: '', accessibleDeptIds: [] } as DeptInfo,
    isAdmin: false
  }),
  actions: {
    setLoginData(res: any) {
      this.token = res.access_token
      this.deptInfo = {
        deptId: res.deptId,
        deptName: res.deptName || '',
        accessibleDeptIds: res.accessibleDeptIds || []
      }
      this.isAdmin = res.deptId === null // 管理员无部门信息
    }
  }
})
